var express = require('express');
var router = express.Router();

var userModel = require('../models/userModel');
var indexModel = require('../models/indexModel');


router.all('/', function(req, res, next) {
	var loginbean = req.session.loginbean;
	indexModel.index(req, res, loginbean);
});

router.get('/login', function(req, res, next) {
  res.render('login', {  });
});

router.post('/login', function(req, res, next) {
	userModel.login(req, res);
});

router.get('/register', function(req, res, next) {
  res.render('register', {  });
});

router.post('/register', function(req, res, next) {
  userModel.register(req, res);
});

router.get('/loginOut', function(req, res) {
	req.session.destroy(function (err) {
		res.redirect('/');
	});
});

router.post('/nextPage', function(req, res, next) {
  var loginbean = req.session.loginbean;
  indexModel.nextPage(req, res, loginbean);
});


module.exports = router;
